home *** CD-ROM | disk | FTP | other *** search
- Imports System.Data
- Imports System.Data.OleDb
- Imports System.Data.SqlClient
-
- ' This form demonstrates how to leverage several features
- ' of List controls
-
- Public Class ListControlsForm
- Inherits System.Web.UI.Page
- Protected WithEvents lstPublishers As System.Web.UI.WebControls.ListBox
- Protected WithEvents lblListBoxInfo As System.Web.UI.WebControls.Label
- Protected WithEvents cblContinents As System.Web.UI.WebControls.CheckBoxList
- Protected WithEvents rblWeekdays As System.Web.UI.WebControls.RadioButtonList
- Protected WithEvents lblDropDownListInfo As System.Web.UI.WebControls.Label
- Protected WithEvents lblCheckBoxListInfo As System.Web.UI.WebControls.Label
- Protected WithEvents lblRadioButtonListInfo As System.Web.UI.WebControls.Label
- Protected WithEvents ddlColors As System.Web.UI.WebControls.DropDownList
-
- #Region " Web Form Designer Generated Code "
-
- 'This call is required by the Web Form Designer.
- <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
-
- End Sub
-
- Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
- 'CODEGEN: This method call is required by the Web Form Designer
- 'Do not modify it using the code editor.
- InitializeComponent()
- End Sub
-
- #End Region
-
- Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
- 'Put user code to initialize the page here
-
- If Not Page.IsPostBack Then
- ' Fill a string array with the names of all known colors.
- Dim colors() As String = [Enum].GetNames(GetType(System.Drawing.KnownColor))
- ' Bind it to the ddlColors dropdownlist control.
- ddlColors.DataSource = colors
-
- #Const USE_DATATEXTFORMATSTRING = False
-
- #If USE_DATATEXTFORMATSTRING = False Then
- ' Open a connection to Biblio.mdb and create a DataReader.
- Dim cn As New OleDbConnection(BiblioConnString)
- Dim cmd As New OleDbCommand("SELECT PubId,Name FROM Publishers", cn)
- cn.Open()
- Dim dr As OleDbDataReader = cmd.ExecuteReader(CommandBehavior.CloseConnection)
- ' Bind the DataReader to the ListBox control.
- lstPublishers.DataSource = dr
- lstPublishers.DataTextField = "Name"
- lstPublishers.DataValueField = "PubId"
- #Else
- ' Open a connection to Pubs and create a DataReader.
- Dim cn As New OleDbConnection(OledbPubsConnString)
- Dim cmd As New OleDbCommand("SELECT * FROM Titles", cn)
- cn.Open()
- Dim dr As OleDbDataReader = cmd.ExecuteReader(CommandBehavior.CloseConnection)
- ' Bind the DataReader to the ListBox control.
- lstPublishers.DataSource = dr
- lstPublishers.DataTextField = "pubdate"
- lstPublishers.DataValueField = "title_id"
- lstPublishers.DataTextFormatString = "{0:D}"
- #End If
-
- ' Creating the collection of radio buttons via code.
- Dim i As Integer
- For i = 1 To 7
- Dim li As New ListItem(WeekdayName(i), i.ToString)
- rblWeekdays.Items.Add(li)
- Next
-
- ' Create a HashTable with continent names.
- Dim continents As New Hashtable(5)
- continents.Add("America", 1)
- continents.Add("Europa", 2)
- continents.Add("Asia", 3)
- continents.Add("Africa", 4)
- continents.Add("Australia", 5)
-
- ' Bind it to the cblContinents CheckBoxList control.
- cblContinents.DataSource = continents
- cblContinents.DataTextField = "Key"
- cblContinents.DataValueField = "Value"
-
- ' Perform binding for all the controls in the page.
- Me.DataBind()
-
- ' Close the DataReader (and the Connection.)
- dr.Close()
- End If
-
- End Sub
-
- ' a new item in the multiselect ListBox control has been selected
-
- Private Sub lstPublishers_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles lstPublishers.SelectedIndexChanged
- Dim li As ListItem, msg As String
- ' check the Selected property of each element in the list
- For Each li In lstPublishers.Items
- If li.Selected Then
- msg &= String.Format("Item = {0}, Value = {1} <br>", li.Text, li.Value)
- End If
- Next
- lblListBoxInfo.Text = msg
- End Sub
-
- ' an element of the DropDownList control has been selected
-
- Private Sub ddlColors_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ddlColors.SelectedIndexChanged
- With ddlColors.SelectedItem
- lblDropDownListInfo.Text = "Item = " & .Text & ", Value = " & .Value
- End With
- End Sub
-
- ' an element of the RadioButtonList control has been selected
-
- Private Sub rblWeekdays_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles rblWeekdays.SelectedIndexChanged
- With rblWeekdays.SelectedItem
- lblRadioButtonListInfo.Text = "Item = " & .Text & ", Value = " & .Value
- End With
- End Sub
-
- ' an element of the CheckBoxList control has been selected
-
- Private Sub cblContinents_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles cblContinents.SelectedIndexChanged
- Dim li As ListItem, msg As String
- ' check the Selected property of each item
- For Each li In cblContinents.Items
- If li.Selected Then
- msg &= String.Format("Item = {0}, Value = {1}<br>", li.Text, li.Value)
- End If
- Next
- lblCheckBoxListInfo.Text = msg
- End Sub
-
- End Class
-